<html>
<head>
  <script type="text/javascript" src="../../zepto.min.js"></script>
  <script type="text/javascript" src="../../assert.js"></script>
</head>
<body>
<script>
  var gui = require('nw.gui');

  var menu = new gui.Menu();

  menu.append(new gui.MenuItem({ type: 'checkbox', label: 'Sub 1', checked: true, enabled: false }));
  menu.append(new gui.MenuItem({ type: 'checkbox', label: 'Sub 2', checked: false, enabled: true }));
  menu.append(new gui.MenuItem({ type: 'checkbox', label: 'Sub 3', checked: false, enabled: true }));
  menu.append(new gui.MenuItem({ type: 'checkbox', label: 'Sub 4', checked: false, enabled: true }));

  // Click to flip other items
  var lastone = menu.items[0];
  menu.items[0].click = menu.items[1].click = menu.items[2].click = menu.items[3].click = function() {
    lastone.checked = false;
    lastone.enabled = true;
    this.enabled = false;
    lastone = this;
  }

  var tray = new gui.Tray({
    title: 'Test Tray',
    icon: 'icon.png',
    menu: menu
  });

  assert(
  tray.icon == 'icon.png',
  'Initial Tray Icon');

  tray.icon = '';
  assert(
  tray.icon == '',
  'Clear Tray Icon');

  tray.icon = 'icon.png';

  assert(
  tray.title == 'Test Tray',
  tray.tooltip == '',
  tray.menu == menu,
  'Init Tray');

  tray.title = 'Love Tray';
  tray.tooltip = 'Love Tooltip';
  assert(
  tray.title == 'Love Tray',
  tray.tooltip == 'Love Tooltip',
  'Change Tray');

  var tray2 = new gui.Tray({
    title: 'Test Tray 2',
    menu: menu
  });

  assert(
  tray.menu == tray2.menu,
  tray2.title == 'Test Tray 2',
  'Second Tray');

  tray.on('click', function() {
    console.log('click on tray');
  });

  gc();

</script>
</body>
</html>
